package com.maoye.ossp.biz.statement.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.hotent.base.api.query.QueryFilter;
import com.maoye.ossp.biz.statement.entity.StatementOrder;
import com.maoye.ossp.biz.statement.entity.StatementOrderDetail;
import com.maoye.ossp.biz.statement.service.StatementOrderDetailService;
import com.maoye.ossp.common.entity.Page;
import com.maoye.ossp.common.excel.ExportExcel;
import com.maoye.ossp.common.web.BaseController;
/**
 * 订单明细controller类
 * @author yanghao
 *
 */
@Controller
@RequestMapping(value = "biz/statement/statementOrderDetail/")
public class StatementOrderDetailController extends BaseController {
	
	@Resource
	private StatementOrderDetailService statementOrderDetailService;
	/**
	 * 查看订单明细列表
	 * @param statementOrder
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "list")
	public String list(StatementOrderDetail statementOrderDetail, HttpServletRequest request,
			HttpServletResponse response, Model model) {
		String orderNo = request.getParameter("orderNo");
		QueryFilter queryFilter = getQuerFilter(request, statementOrderDetail);
		queryFilter.getParams().put("billNo", orderNo);
		Page<StatementOrderDetail> page = (Page<StatementOrderDetail>) statementOrderDetailService
				.find(queryFilter);
		model.addAttribute("page", page);
		return resultPage("/biz/statement/statementOrderDetail/list", model, request);
	}
	
	/**
	 * 查看订单明细列表详细信息
	 * @param statementOrder
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
	@RequestMapping(value = "view")
	public String view(StatementOrderDetail statementOrderDetail, HttpServletRequest request,
			HttpServletResponse response, Model model) {
		String id = statementOrderDetail.getId().toString();
		StatementOrderDetail statementOrderDetail1 =  statementOrderDetailService.get(id);
		model.addAttribute("statementOrderDetail", statementOrderDetail1);
		return "/biz/statement/statementOrderDetail/view";
	}
	/**
	 * 导出数据到Excel
	 * @param request
	 * @param model
	 * @param redirectAttributes
	 * @return
	 */
	@RequestMapping(value = "exportExcel")
	public String exportExcel (HttpServletRequest request,Model model,RedirectAttributes redirectAttributes){
		String orderNo = request.getParameter("orderNo");
		Map map = new HashMap();
		map.put("billNo", orderNo);
		List<StatementOrderDetail> list = statementOrderDetailService.getByBillNo(map);
		Class clx = StatementOrderDetail.class;
		ExportExcel.exportExcel(orderNo+"订单明细表", list, StatementOrderDetail.class, request);
		return "/excel/exceportToExcel";
	}
	public StatementOrderDetailService getStatementOrderDetailService() {
		return statementOrderDetailService;
	}

	public void setStatementOrderDetailService(
			StatementOrderDetailService statementOrderDetailService) {
		this.statementOrderDetailService = statementOrderDetailService;
	}
	

}
